<template>
  <div class="addBidding">
    <el-card shadow="never">
      <div class="header">
        <div class="page-header">
          <el-page-header @back="goBack" content="投标" style="margin-bottom: 20px">
          </el-page-header>
        </div>

        <div class="bidding">
          <!--     标题     -->
          <el-form :model="tenderForm"  ref="tenderForm" label-width="120px" class="demo-ruleForm">
            <el-form-item label="招标信息" prop="tenderTitle">
              <el-input
                  disabled
                  v-model="tenderForm.tenderTitle"
                  :rows="10"></el-input>
            </el-form-item>
          <el-form-item label="投标价格" prop="biddingPrice">
            <el-input
                v-model="biddingForm.biddingPrice"
                :rows="10"></el-input>
          </el-form-item>
            <el-form-item>
                <el-button :disabled="isDisabled" type="primary" @click="addBidding">确认</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import {addBidding, getTenderById, isAddBiddingByUserIdAndTenderId} from "@/api/allApi";

export default {
  data() {
    return {
      tenderForm:{},
      biddingForm:{},
      user:'',
      isDisabled:false
    }
  },
  created() {
    this.user = JSON.parse(window.localStorage.getItem('access-user'))
  },
  methods:{
    getTenderById() {
      getTenderById(this.$route.params.tenderId).then(res=>{
        this.tenderForm = res.data.data
      })
    },
    goBack() {
      this.$router.back();
    },
    addBidding() {
      this.biddingForm.userId = this.user.userId
      this.biddingForm.tenderId = this.tenderForm.tenderId
      addBidding(this.biddingForm).then(res=>{
        if (res.data.success) {
          this.$message.success(res.data.data)
          this.$router.push("/userLayout/moreInformation")
          this.biddingForm = {}
        }
        else {
          this.$message.error(res.data.data)
        }
      })
    },
    isAddBiddingByUserIdAndTenderId() {
      isAddBiddingByUserIdAndTenderId({
        userId:this.user.userId,
        tenderId:Number(this.$route.params.tenderId)
      }).then(res=>{
        if (res.data.success) {

        }
        else {
          this.isDisabled = true
          this.$message.error(res.data.errorMsg)
        }
      })
    }
  },
  mounted() {
    this.getTenderById()
    this.isAddBiddingByUserIdAndTenderId()
  }
}
</script>

<style lang="less" scoped>
  .addBidding {
    width: 80%;
    margin: 30px auto;
    min-width: 900px;
    flex-wrap: wrap;

    .bidding {
      padding: 50px;
      min-height: 450px;
      margin: 0 auto;
      width: 500px;
    }
  }
</style>